import request from '@/utils/request'

export function getSpuListApi (page, limit, category3Id) {
  return request({
    url: `/admin/product/${page}/${limit}`,
    method: 'get',
    params: { category3Id }
  })
}

export function getSpuInfoApi (spuId) {
  return request({
    url: `/admin/product/getSpuById/${spuId}`,
    method: 'get'
  })
}

export const getTrademarkListApi = () => {
  return request({
    url: '/admin/product/baseTrademark/getTrademarkList',
    method: 'get'
  })
}

export const getSpuImageListApi = (spuId) => request({
  url: `/admin/product/spuImageList/${spuId}`,
  method: 'get'
})

export function getBaseSaleAttrListApi () {
  return request({
    url: '/admin/product/baseSaleAttrList',
    method: 'get'
  })
}

// 修改或添加spu,携带给服务器的参数大致相同,唯一区别在于是否携带了id
export function addOrUpdateSpuApi (spuInfo) {
  // 如果有id -> 修改spu
  if (spuInfo.id) {
    return request({
      url: '/admin/product/updateSpuInfo',
      method: 'post',
      data: spuInfo
    })
  } else {
    return request({
      url: '/admin/product/saveSpuInfo',
      method: 'post',
      data: spuInfo
    })
  }
}

// 删除spu
export function deleteSpuApi (spuId) {
  return request({
    url: `/admin/product/deleteSpu/${spuId}`,
    method: 'delete'
  })
}
